/**
 * Created by 15c on 2018/2/4.
 *
 * 个人中心页
 */
app.controller("personal-center", function ($http, $scope) {
    //证书
    var token = localStorage.getItem('token');
    //用户信息对象
    $scope.showCircle=false;
    $scope.userInfo = {};
    $scope.getPerInfo = function () {
        if (token) {
            $http({
                method: 'get',
                url: app.netPath + '/users/details/show',
                headers: {'Authorization': token}
            }).then(function (res) {
                if (!res.data.error) {
                    $scope.userInfo = res.data.data;
                    console.log(res.data.data);

                    var avatarImg = {};

                    if (res.data.data.userAvatarAddress) {
                        avatarImg.imgAddress = app.netPath + '/resources/img/' + res.data.data.userAvatarAddress;
                        $scope.userInfo.avatarImg = avatarImg;
                    }
                    $scope.aHref = "#/personal-information";
                    if ($scope.userInfo.userNickName) {
                        $scope.words = $scope.userInfo.userNickName;
                    } else {
                        $scope.words = "不一样的昵称，不一样的心情";
                    }

                }
                else {
                    $.toast(res.data.error + ',' + res.data.msg);
                }
            }, function () {
                $.toast('网络走丢了！')
            });
            //获取该用户的消息条数
            $http({
                method: 'get',
                url: app.netPath + '/interaction/show/mynews/count',
                headers: {Authorization: token}
            }).then(function (res) {
                if (!res.data.error) {
                    if (res.data.data != 0) {
                        $scope.showCircle=true;
                        //$("#point").css("display", "none");
                    }

                }

            }, function () {
                $.toast('网络走丢了！')
            });

        } else {
            $scope.words = "登录/注册";
            $scope.aHref = "#/user-login";
            $("#point").css("display", "none");
        }

    }
});